package exist;

public class QueryProxy implements exist.Query {
  private String _endpoint = null;
  private exist.Query query = null;
  
  public QueryProxy() {
    _initQueryProxy();
  }
  
  public QueryProxy(String endpoint) {
    _endpoint = endpoint;
    _initQueryProxy();
  }
  
  private void _initQueryProxy() {
    try {
      query = (new exist.QueryServiceLocator()).getQuery();
      if (query != null) {
        if (_endpoint != null)
          ((javax.xml.rpc.Stub)query)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
        else
          _endpoint = (String)((javax.xml.rpc.Stub)query)._getProperty("javax.xml.rpc.service.endpoint.address");
      }
      
    }
    catch (javax.xml.rpc.ServiceException serviceException) {}
  }
  
  public String getEndpoint() {
    return _endpoint;
  }
  
  public void setEndpoint(String endpoint) {
    _endpoint = endpoint;
    if (query != null)
      ((javax.xml.rpc.Stub)query)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
    
  }
  
  public exist.Query getQuery() {
    if (query == null)
      _initQueryProxy();
    return query;
  }
  
  public java.lang.String getResource(java.lang.String sessionId, java.lang.String path, boolean indent, boolean xinclude) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.getResource(sessionId, path, indent, xinclude);
  }
  
  public exist.QueryResponse query(java.lang.String sessionId, java.lang.String xpath) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.query(sessionId, xpath);
  }
  
  public java.lang.String connect(java.lang.String userId, java.lang.String password) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.connect(userId, password);
  }
  
  public java.lang.String[] retrieve(java.lang.String sessionId, int start, int howmany, boolean indent, boolean xinclude, java.lang.String highlight) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.retrieve(sessionId, start, howmany, indent, xinclude, highlight);
  }
  
  public void disconnect(java.lang.String sessionId) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    query.disconnect(sessionId);
  }
  
  public byte[] getResourceData(java.lang.String sessionId, java.lang.String path, boolean indent, boolean xinclude, boolean processXSLPI) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.getResourceData(sessionId, path, indent, xinclude, processXSLPI);
  }
  
  public exist.QueryResponse xquery(java.lang.String sessionId, byte[] xquery) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.xquery(sessionId, xquery);
  }
  
  public byte[][] retrieveData(java.lang.String sessionId, int start, int howmany, boolean indent, boolean xinclude, java.lang.String highlight) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.retrieveData(sessionId, start, howmany, indent, xinclude, highlight);
  }
  
  public java.lang.String[] retrieveByDocument(java.lang.String sessionId, int start, int howmany, java.lang.String path, boolean indent, boolean xinclude, java.lang.String highlight) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.retrieveByDocument(sessionId, start, howmany, path, indent, xinclude, highlight);
  }
  
  public exist.Collection listCollection(java.lang.String sessionId, java.lang.String path) throws java.rmi.RemoteException{
    if (query == null)
      _initQueryProxy();
    return query.listCollection(sessionId, path);
  }
  
  
}